<template>
  <el-dialog
    :title="$t('AbpIdentity[\'SetPassword\']')"
    :visible.sync="visible"
    :before-close="closeDialog"
    :close-on-click-modal="false"
    width="30%"
  >
    <el-form
      ref="form"
      label-position="top"
      :model="form"
    >
      <el-form-item :label="$t('AbpIdentity[\'DisplayName:Password\']')" prop="newPassword">
        <el-input v-model="form.newPassword" type="password"/>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">{{ $t('AbpIdentity[\'Cancel\']') }}</el-button>
      <el-button type="primary" @click="submitForm">
        <i class="el-icon-check" />
        {{ $t('AbpIdentity[\'Save\']') }}
      </el-button>
    </span>
  </el-dialog>
</template>

<script>

import {
  changePassword
} from '@/api/administration/user/user'
export default {
  name: 'SetPassword',
  props: {
    context: {
      type: Object,
      required: true
    },
    visible: {
      type: Boolean,
      required: true,
      default: false
    }
  },
  data() {
    return {
      form: {
        newPassword: ''
      }
    }
  },
  created() {
  },
  methods: {
    async submitForm() {
      await changePassword(this.context.user.id, { newPassword: this.form.newPassword })
      this.$message({ message: this.$t('AbpIdentity[\'Ok\']'), type: 'success' })
      this.closeDialog()
    },
    closeDialog() {
      this.resetDialog() // 重置表单
      this.$emit('update:visible', false)
    },
    resetDialog() {
      this.$refs.form.resetFields()
    }
  }
}
</script>

<style scoped>
</style>
